#ifndef UTILS_H
#define UTILS_H

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>

#define PHI (24.0f/100.0f)
#define PI (3.14159f)

#define MAX_THREADS 16

#define DEG2RAD(d,r) do{r=PI/180*d;}while(0)

#define DEBUG 0

#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"

typedef struct timeval timeVal;

typedef struct
{
	unsigned int tid;

	int dimX;
	int dimY;
	int offsetY;
} thread_data;

/* Function: calcRuntime */
unsigned long calcRuntime(timeVal start, timeVal end)
{
	/* calc time difference */
	timeVal diff;
	diff.tv_sec = end.tv_sec - start.tv_sec;
	if (start.tv_usec > end.tv_usec)
	{
		diff.tv_usec = (1e6 - end.tv_usec) + start.tv_usec;
	}
	else
	{
		diff.tv_usec = end.tv_usec - start.tv_usec;
	}
	
	return diff.tv_sec * 1e6 + diff.tv_usec;
}


/*Function: usage*/
void usage(void){
	printf("Syntax Error!\n");
	printf("Usage: ./heatdist <iterations> <size> <heat radius> <heat value> <no. of threads [max.: 16 ]>\n");
	exit(-1);
}


#endif
